<template>
  <el-dialog @close="gcjljjjdCancel('gcjljjjdRuleForm')" :close-on-click-modal="false" title="拒绝接单"
    :visible.sync="gcjljjjdVisible" append-to-body width="600px">
    <div class="scroll-view">
      <el-form :model="gcjljjjdRuleForm" :rules="gcjljjjdRules" ref="gcjljjjdRuleForm" label-position="top">
        <el-form-item label="拒绝理由" prop="remark">
          <el-input :rows="4" class="input-box" v-model="gcjljjjdRuleForm.remark" type="textarea"></el-input>
        </el-form-item>
      </el-form>

    </div>
    <span slot="footer">
      <el-button type="primary" @click="gcjljjjdSubmit('gcjljjjdRuleForm')" :disabled="diaLoading"
        :loading="diaLoading">提交</el-button>
        <el-button @click="gcjljjjdCancel('gcjljjjdRuleForm')">关闭</el-button>
    </span>
  </el-dialog>
</template>
<script>
import projectApi from "@/api/projectApi";

export default {
  name: "",
  props: {
    addDialogVisible: {
      type: Boolean,
      default: false,
      required: false,
    },
    project_id: {
      required: false,
    },
  },
  data() {
    return {
      diaLoading: false,
      gcjljjjdVisible: false,
      gcjljjjdRuleForm: {
        remark: "",
      },
      gcjljjjdRules: {
        remark: [
          { required: true, message: "请输入拒绝理由", trigger: "change" },
        ],
      },
    };
  },
  watch: {
    addDialogVisible(val1, val2) {
      this.gcjljjjdVisible = this.addDialogVisible;
    },
  },
  computed: {},
  mounted() { },
  methods: {
    // 工程经理拒绝接单
    gcjljjjdCancel(formName) {
      this.gcjljjjdRuleForm = {
        remark: "",
      };
      this.$nextTick(() => {
        this.$refs[formName].clearValidate();
        this.$emit("onClose", true);
      });
    },
    gcjljjjdSubmit(formName) {
      let gcjljjjdRuleForm = this.gcjljjjdRuleForm;
      console.log(gcjljjjdRuleForm, "工程经理拒绝接单参数");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.diaLoading = true;
          projectApi
            .refuseAssignment({
              project_id: this.project_id,
              remark: gcjljjjdRuleForm.remark,
            })
            .then((res) => {
              console.log(res, "工程经理拒绝接单");
              this.diaLoading = false;
              if (res.code == 200) {
                this.$emit("onSuccess", true);
              }
              this.$message({
                type: res.code == 200 ? "success" : "warning",
                message: res.code == 200 ? "处理成功" : res.message,
              });
            })
            .catch((err) => {
              this.diaLoading = false;
              this.$message({
                type: "warning",
                message: err.message,
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>